package packet1;
import java.util.*;
public class test_huawei {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n,m;
        n = sc.nextInt();
        m = sc.nextInt();
        sc.nextLine();
        String[] s = new String[m * 2];
        String[] re = new String[n];
        for(int i = 0; i < m * 2; i++)
        {
            s[i] = sc.nextLine();
        }
        Map<String,Integer> map = new LinkedHashMap<>();
        for(int i = 0; i < m * 2; i++)
        {
            String[] splited = s[i].split(" ");
            for(String s1 : splited)
            {
                if(i % 2 == 0){
                    if(map.containsKey(s1))
                        map.put(s1,map.get(s1) + 3);
                    else
                        map.put(s1,3);
                }
                else
                {
                    if(map.containsKey(s1))
                        map.put(s1,map.get(s1) + 1);
                    else
                        map.put(s1,1);
                }

            }
        }
        List<Map.Entry<String,Integer>> list = new ArrayList<>(map.entrySet());
        //降序排序
        //Collections.sort(list, (o1, o2) -> o2.getValue().compareTo(o1.getValue()));

        Collections.sort(list,new Comparator<Map.Entry<String,Integer>>() {
            //降序排序
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o2.getValue().compareTo(o1.getValue());
            }
        });
        int i = 0;
        for(Map.Entry<String,Integer> entry:list ){
            re[i] = entry.getKey();
            i++;
            if(i >= n)
                break;;
        }
        for(String re1 : re)
            System.out.print(re1 + " ");

    }
}
